/*
 * Copyright (C) 2000-2008 Jens Nixdorf and various contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies of the Software, its documentation and marketing & publicity
 * materials, and acknowledgment shall be given in the documentation, materials
 * and software packages that this Software was used.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.mopore.jat.gui.wizard;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

public class ButtonPanel {
	
	private final JButton backButton;
	
	private final JButton nextButton;
	
	private final JButton finishButton;
	
	private final JButton cancelButton;
	
	private final JPanel panel;
	
	private WizardContext<?> context;
	
	
	public ButtonPanel(){
		
		Border border = BorderFactory.createEtchedBorder( EtchedBorder.LOWERED );
		this.panel = new JPanel();
		panel.setBorder( border );
		panel.setLayout( new FlowLayout() );
		
		backButton = new JButton( "< back" );
		backButton.setEnabled( false );
		panel.add( backButton );
		
		nextButton = new JButton( "next >" );
		nextButton.setEnabled( false );
		panel.add( nextButton );
		
		finishButton = new JButton( "finish" );
		finishButton.setEnabled( false );
		finishButton.addActionListener( new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				IWizard<?> wizard = context.getWizard();
				wizard.release( true );
			}} );
		panel.add( finishButton );
		
		cancelButton = new JButton( "cancel" );
		cancelButton.setEnabled( true );
		cancelButton.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				IWizard<?> wizard = context.getWizard();
				wizard.release( false );
			}} );		
		panel.add( cancelButton );
		
	}
	
	
	public JPanel getPanel(){
		return panel;
	}
	
	public void enableBackButton(){
		backButton.setEnabled( true );
	}
	
	public void disableBackButton(){
		backButton.setEnabled( false );
	}
	
	public void addActionToBackButton( ActionListener action ){
		backButton.addActionListener( action );
	}
	
	public void enableNextButton(){
		nextButton.setEnabled( true );
	}
	
	public void disableNextButton(){
		nextButton.setEnabled( false );
	}
	
	public void addActionToNextButton( ActionListener action ){
		nextButton.addActionListener( action );
	}
	
	public void enableFinishButton(){
		finishButton.setEnabled( true );
	}
	
	public void disableFinishButton(){
		finishButton.setEnabled( false );
	}
	
	public void addActionToFinishButton( ActionListener action ){
		finishButton.addActionListener( action );
	}
	
	public void enableCancelButton(){
		cancelButton.setEnabled( true );
	}
	
	public void disableCancelButton(){
		cancelButton.setEnabled( false );
	}
	
	public void addActionToCancelButton( ActionListener action ){
		cancelButton.addActionListener( action );
	}


	public void setWizardContext(WizardContext<?> context) {
		this.context = context;
	}
	
}
